package tester.outcome.person;

import messages.observer.EventCollectionMessage;
import state.group.events.BaseEvent;
import state.group.events.EventCollection;
import state.group.events.EventType;
import state.person.events.GoingInEvent;
import tester.outcome.BaseEventOutcome;

/**
 * This class looks for a person going in event
 * @author Caleb Chan
 *
 */
public class PersonGoingInOutcome extends BaseEventOutcome {

	private String person;
	
	/**
	 * PersonGoingInOutcome constructor
	 * @param startTime The start time of the outcome
	 * @param person The name of the person to be check against
	 */
	public PersonGoingInOutcome(long startTime, String person) {
		super(startTime);
		this.person = person;
	}

	@Override
	public boolean checkOutcome(EventCollectionMessage message) {
		
		EventCollection collection = message.getEvents();
		
		for(BaseEvent e : collection){
			// Check for a going in event
			if (e.getEventType() == EventType.GoingInEvent){
				GoingInEvent rE = (GoingInEvent)e;
				// Makes sure the person name is the same
				if (rE.getPersonId().toString().equals(person)){
					isCompleted = true;
				}
			}
		}
		return isCompleted;
	}
	
	/**
	 * This method returns the name of person being check against
	 * @return Returns the name of the person
	 */
	public String getPerson(){
		return person;
	}

	@Override
	public String getOutcomeName() {
		return "PersonGoingInOutcome";
	}

	@Override
	public BaseEventOutcome copy() {
		return new PersonGoingInOutcome(0, person);
	}

	@Override
	public String getOutcomeChecksStr() {
		return getOutcomeName() + " Name -> " + person;
	}
}
